package com.neuedu.studentmanage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neuedu.studentmanage.entity.Result;
import com.neuedu.studentmanage.entity.User;
import com.neuedu.studentmanage.service.UserService;

@Controller
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping("admin/passEdit")
	@ResponseBody
	public Result passEdit(String password,String ackPassword, String userName, Model model) {
		User user = new User(userName, password);
		Result result = new Result(false, "修改密码失败");
		if (userService.login(user) == null) {
			result = new Result(false, "修改失败，原密码错误！");
		}else {
			boolean b1 = ackPassword == null || ackPassword.trim().length() == 0;
			boolean b2 = userName == null || userName.trim().length() == 0;
			
			if (!b1 || !b2) {
				User user1 = new User(userName, ackPassword);
				result = userService.edit(user1);
			}
		}
		return result;
	}

}
